package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JLabel;

import model.Model;
import view.items.PanelTitre;
import controller.Controller;
import controller.Outils;

public class ViewInformation extends ViewAbstract {

	private Model model;
	private Controller controller;

	public ViewInformation(Controller controller, int x, int y, int width, int height) {
		this.model=controller.getModel();
		this.controller = controller;
		this.setBackground(Color.lightGray);
		this.setBounds(x,y,width,height);
		this.refresh();
		this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 1));
	}

	public void refresh() {
		//System.out.println("refreshViewInformation");
		this.removeAll();
		//Partie statique
		PanelTitre titre = new PanelTitre("My information");
		this.add(titre);
		
		
		JLabel firstName = new JLabel("Last Name : " + model.getProperties().getProperty("lastname"));
		firstName.setPreferredSize(new Dimension(290, 15));
		this.add(firstName);
		JLabel lastName = new JLabel("First Name : "+model.getProperties().getProperty("firstname"));
		lastName.setPreferredSize(new Dimension(290, 15));
		this.add(lastName);
		
		JLabel yourip = new JLabel("IP : ");
		yourip.setPreferredSize(new Dimension(290, 15));
		this.add(yourip);
		for (String ip : Outils.getIps()) {
			if(Outils.checkIp(ip) && !ip.equals("127.0.0.1")){
			JLabel iplabel = new JLabel(ip);
			iplabel.setPreferredSize(new Dimension(290, 15));
			this.add(iplabel);
			}
		}
		
		
		JLabel portEnEcoute = new JLabel("Listening TCP port : "+model.getProperties().getProperty("tcp_port"));
		portEnEcoute.setPreferredSize(new Dimension(290, 15));
		this.add(portEnEcoute);
		
		JButton editInfo = new JButton("Edit..");
		editInfo.setActionCommand("change");
		editInfo.addActionListener(controller);

		this.add(editInfo);
		
		
		this.repaint();
		this.revalidate();
	}

}
